Wikipedia para siempre
TreeWeb::Artículos::Golang::Golang convert from map[string] to struct
Permalink: http://www.treeweb.es/u/1313/ 05/02/2016

Golang convert from map[string] to struct

package main import ( "encoding/json" "fmt" ) type User struct { Name string `json:"name"` } func FillStruct(m map[string]interface{}, s interface{}) { j, _ := json.Marshal(m) json.Unmarshal(j, s) } func main() { // Initial map user_map := map[string]interface{}{ "name": "Fulanito", } fmt.Println(user_map) // Empty User user_object := &User{} // Fill Object FillStruct(user_map, user_object) fmt.Println(user_object.Name) }

Try it!